﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace MagicBag.CRM.Web.Test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            DataColumn colID = new DataColumn("ID", Type.GetType("System.Int32"));
            DataColumn colName = new DataColumn("Name", Type.GetType("System.String"));
            dt.Columns.Add(colID);
            dt.Columns.Add(colName);
            DataRow dr1 = dt.NewRow();
            DataRow dr2 = dt.NewRow();
            DataRow dr3 = dt.NewRow();
            DataRow dr4 = dt.NewRow();
            dr1[0] = 1;
            dr1[1] = "aaa";
            dr2[0] = 3;
            dr2[1] = "bbb";
            dr3[0] = 5;
            dr3[1] = "ccc";
            dr4[0] = 7;
            dr4[1] = "SCG";

            dt.Rows.Add(dr1);
            dt.Rows.Add(dr2);
            dt.Rows.Add(dr3);
            dt.Rows.Add(dr4);
            EnumerableRowCollection<DataRow> dt1 = dt.AsEnumerable();

            EnumerableRowCollection<DataRow> erc2 = from dr in dt1 where Convert.ToInt32(dr["ID"]) >= 7 select dr;


            EnumerableRowCollection<DataRow> erc3 = from dr in dt1 where dr["Name"].ToString().Contains("cx") select dr;

            IEnumerable<DataRow> erc4 = erc2.Union<DataRow>(erc3.AsEnumerable());//合并

            if (erc4.Count() > 0)
                dt = erc4.CopyToDataTable<DataRow>();
            else
                dt = null;

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}